<?php

namespace app\modules\setting\models\seller;

use app\common\enum\EtcSellerTiktokProduct_shStatusEnum;
use sookie\auth\models\Adminuser;
use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use yii\db\Expression;
use yii\helpers\ArrayHelper;
use app\modules\setting\models\seller\EtcSellerTiktokProduct;
use yii\helpers\Json;

/**
 * EtcSellerTiktokProductSearch 是 `app\modules\setting\models\seller\EtcSellerTiktokProduct` 的搜索模型.
 */
class EtcSellerTiktokProductSearch extends EtcSellerTiktokProduct
{


    /**
     * @inheritdoc
     */
    public function scenarios()
    {
        // 绕过scenario()在父类中的实现
        return Model::scenarios();
    }

    /**
     * Creates data provider instance with search query applied
     *
     * @param array $params
     *
     * @param integer $pageSize
     *
     * @return ActiveDataProvider
     */
    public function search($params,$select=null)
    {
        $query = EtcSellerTiktokProduct::find()->select($select ? $select : "*");

        $info = Adminuser::getUserInfo();
        $query->andWhere(['user_id' => $info->id]);

        $dataProvider = new ActiveDataProvider([
            'query' => $query,
            'pagination' => ['pageSize' => ArrayHelper::getValue($params,"pageSize",10),'defaultPageSize' => 10,'pageSizeParam' => 'pageSize'],
            'sort' => ['defaultOrder' => ['id' => SORT_DESC]],
        ]);

        $this->load($params,"");

        if (!$this->validate()) {
            // 如果您不想在验证失败时返回任何记录，请取消下面一行的注释
            // $query->where('0=1');
            return $dataProvider;
        }

        // 过滤条件
        $query->andFilterWhere([
            'id' => $this->id,
        ]);


                $query->andFilterWhere(['like', 'goods_id', $this->goods_id])                                ->andFilterWhere(['like', 'user_id', $this->user_id])
                                ->andFilterWhere(['like', 'name', $this->name])
                                ->andFilterWhere(['like', 'price', $this->price])
                                ->andFilterWhere(['like', 'min_price', $this->min_price])
                                ->andFilterWhere(['like', 'max_price', $this->max_price])
                                ->andFilterWhere(['like', 'creator_commission_percent', $this->creator_commission_percent])
                                ->andFilterWhere(['like', 'seller_commission_percent', $this->seller_commission_percent])
                                ->andFilterWhere(['like', 'product_id', $this->product_id])
                                ->andFilterWhere(['like', 'product_rating', $this->product_rating])
                                ->andFilterWhere(['like', 'product_review_count', $this->product_review_count])
                                ->andFilterWhere(['like', 'product_sales', $this->product_sales])
                                ->andFilterWhere(['like', 'seller_id', $this->seller_id])
                                ->andFilterWhere(['like', 'shop_code', $this->shop_code])
                                ->andFilterWhere(['like', 'sample_quota', $this->sample_quota])
                                ->andFilterWhere(['like', 'content', $this->content])
                                ->andFilterWhere(['like', 'img', $this->img])
                                ->andFilterWhere(['like', 'link', $this->link])
                                ->andFilterWhere(['like', 'product_link', $this->product_link])
                                ->andFilterWhere(['like', 'created_at', $this->created_at])
                                ->andFilterWhere(['like', 'type', $this->type])
                                ->andFilterWhere(['like', 'campaign_id', $this->campaign_id])
                                ->andFilterWhere(['like', 'seller_info', $this->seller_info])
                                ->andFilterWhere(['like', 'use_info', $this->use_info])
                                ->andFilterWhere(['like', 'video_info', $this->video_info])
                                ->andFilterWhere(['like', 'is_edit', $this->is_edit])
                                ->andFilterWhere(['like', 'is_select', $this->is_select]);
            
        return $dataProvider;
    }


    /**
     * Creates data provider instance with search query applied
     *
     * @param array $params
     *
     * @param integer $pageSize
     *
     * @return ActiveDataProvider
     */
    public function searchOffice($params,$select=null)
    {
        $query = EtcSellerTiktokProduct::find()->alias("t")->select($select ? $select : "*");
        $query->andWhere(['sh_status'=>EtcSellerTiktokProduct_shStatusEnum::PASS]);

        $dataProvider = new ActiveDataProvider([
            'query' => $query,
            'pagination' => ['pageSize' => ArrayHelper::getValue($params,"pageSize",10),'defaultPageSize' => 10,'pageSizeParam' => 'pageSize'],
            'sort' => ['defaultOrder' => ['id' => SORT_DESC]],
        ]);

        $this->load($params,"");

        if (!$this->validate()) {
            // 如果您不想在验证失败时返回任何记录，请取消下面一行的注释
            // $query->where('0=1');
            return $dataProvider;
        }

        // 过滤条件
        $query->andFilterWhere([
            'id' => $this->id,
        ]);


        $query->andFilterWhere(['like', 'goods_id', $this->goods_id])                                ->andFilterWhere(['like', 'user_id', $this->user_id])
            ->andFilterWhere(['like', 'name', $this->name])
            ->andFilterWhere(['like', 'price', $this->price])
            ->andFilterWhere(['like', 'min_price', $this->min_price])
            ->andFilterWhere(['like', 'max_price', $this->max_price])
            ->andFilterWhere(['like', 'creator_commission_percent', $this->creator_commission_percent])
            ->andFilterWhere(['like', 'seller_commission_percent', $this->seller_commission_percent])
            ->andFilterWhere(['like', 'product_id', $this->product_id])
            ->andFilterWhere(['like', 'product_rating', $this->product_rating])
            ->andFilterWhere(['like', 'product_review_count', $this->product_review_count])
            ->andFilterWhere(['like', 'product_sales', $this->product_sales])
            ->andFilterWhere(['like', 'seller_id', $this->seller_id])
            ->andFilterWhere(['like', 'shop_code', $this->shop_code])
            ->andFilterWhere(['like', 'sample_quota', $this->sample_quota])
            ->andFilterWhere(['like', 'content', $this->content])
            ->andFilterWhere(['like', 'img', $this->img])
            ->andFilterWhere(['like', 'link', $this->link])
            ->andFilterWhere(['like', 'product_link', $this->product_link])
            ->andFilterWhere(['like', 'created_at', $this->created_at])
            ->andFilterWhere(['like', 'type', $this->type])
            ->andFilterWhere(['like', 'campaign_id', $this->campaign_id])
            ->andFilterWhere(['like', 'seller_info', $this->seller_info])
            ->andFilterWhere(['like', 'use_info', $this->use_info])
            ->andFilterWhere(['like', 'video_info', $this->video_info])
            ->andFilterWhere(['like', 'is_edit', $this->is_edit])
            ->andFilterWhere(['like', 'is_select', $this->is_select]);

        return $dataProvider;
    }

    /**
     * Creates data provider instance with search query applied
     *
     * @param array $params
     *
     * @param integer $pageSize
     *
     * @return ActiveDataProvider
     */
    public function searchSellerSh($params,$select=null)
    {
        $query = EtcSellerTiktokProduct::find()->alias("t")->select($select ? $select : "*");
        $query->andWhere(['is_apply'=>1]);

        $dataProvider = new ActiveDataProvider([
            'query' => $query,
            'pagination' => ['pageSize' => ArrayHelper::getValue($params,"pageSize",10),'defaultPageSize' => 10,'pageSizeParam' => 'pageSize'],
            'sort' => ['defaultOrder' => ['id' => SORT_DESC]],
        ]);

        $this->load($params,"");

        if (!$this->validate()) {
            // 如果您不想在验证失败时返回任何记录，请取消下面一行的注释
            // $query->where('0=1');
            return $dataProvider;
        }

        // 过滤条件
        $query->andFilterWhere([
            'id' => $this->id,
        ]);


        $query->andFilterWhere(['like', 'goods_id', $this->goods_id])                                ->andFilterWhere(['like', 'user_id', $this->user_id])
            ->andFilterWhere(['like', 'name', $this->name])
            ->andFilterWhere(['like', 'price', $this->price])
            ->andFilterWhere(['like', 'min_price', $this->min_price])
            ->andFilterWhere(['like', 'max_price', $this->max_price])
            ->andFilterWhere(['like', 'creator_commission_percent', $this->creator_commission_percent])
            ->andFilterWhere(['like', 'seller_commission_percent', $this->seller_commission_percent])
            ->andFilterWhere(['like', 'product_id', $this->product_id])
            ->andFilterWhere(['like', 'product_rating', $this->product_rating])
            ->andFilterWhere(['like', 'product_review_count', $this->product_review_count])
            ->andFilterWhere(['like', 'product_sales', $this->product_sales])
            ->andFilterWhere(['like', 'seller_id', $this->seller_id])
            ->andFilterWhere(['like', 'shop_code', $this->shop_code])
            ->andFilterWhere(['like', 'sample_quota', $this->sample_quota])
            ->andFilterWhere(['like', 'content', $this->content])
            ->andFilterWhere(['like', 'img', $this->img])
            ->andFilterWhere(['like', 'link', $this->link])
            ->andFilterWhere(['like', 'product_link', $this->product_link])
            ->andFilterWhere(['like', 'created_at', $this->created_at])
            ->andFilterWhere(['like', 'type', $this->type])
            ->andFilterWhere(['like', 'campaign_id', $this->campaign_id])
            ->andFilterWhere(['like', 'seller_info', $this->seller_info])
            ->andFilterWhere(['like', 'use_info', $this->use_info])
            ->andFilterWhere(['like', 'video_info', $this->video_info])
            ->andFilterWhere(['like', 'is_edit', $this->is_edit])
            ->andFilterWhere(['like', 'is_select', $this->is_select]);

        return $dataProvider;
    }
}
